//
// evalopcode.c - Display module plug-in routines
//
// Copyright (C) 2001-2007 Massachusetts Institute of Technology
// Contact   Arnan (Roger) Sipiatkiat [arnans@gmail.com]
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//




void sendSensorValues() {
   int i;

   // send command
   i2c_start();
   i2c_write(LCD_ADDRESS | 0);
   i2c_write(CMD_UPDATE_SENSORS);

   // send data
   for (i=0;i<8;i++) {
      i2c_write(gblSensorValues[i] & 0xff);   // low byte
      i2c_write(gblSensorValues[i] >> 8);     // high byte
   }

   i2c_stop();
}

void sendUserDisplayText(char *displayString) {
   int i;

   // send command
   i2c_start();
   i2c_write(LCD_ADDRESS | 0);
   i2c_write(CMD_UPDATE_USER_DISPLAY);

   // send data
   for (i=0;i<4;i++) {
     i2c_write(*(displayString+i));
   }

   i2c_stop();
}

void sendSpecialDisplaySegments(int segmentBuffer) {

   // send command
   i2c_start();
   i2c_write(LCD_ADDRESS | 0);
   i2c_write(CMD_UPDATE_SPECIAL_DISPLAY_SEGMENTS);

   // send data
   i2c_write(segmentBuffer);

   i2c_stop();
}



int getCommandByte() {
   int inbyte;

   /// first, send the command
   i2c_start();
   i2c_write(LCD_ADDRESS | 0);
   i2c_write(CMD_REQUEST_USER_CMD);

   // second, wait for byte
   i2c_start();
   i2c_write(LCD_ADDRESS | 1);  // bit 0 = 1 means Slave will write to master
   delay_ms(1);   // give the slave sometime to respond

   inbyte = i2c_read(0);  // read with out Ack bit
   i2c_stop();
   return(inbyte);
}

